package com.xinai.activity;


import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.xinai.dao.DepartmentDao;
import com.xinai.R;
import com.xinai.dao.ParamerDao;
import com.xinai.dao.SysDepartmentDao;
import com.xinai.dao.SysUsersDao;
import com.xinai.dao.sysBarcodeDao;
import com.xinai.util.AppManager;
import com.xinai.util.JsonHelper;
import com.xinai.util.Logger;
import com.xinai.util.LoginParameterUtil;
import com.xinai.util.NetUtil;
import com.xinai.util.Tools;
import com.xinai.util.gridview.MyGridAdapter;
import com.xinai.util.gridview.MyGridView;
import com.xinai.vo.Department;
import com.xinai.vo.Paramer;
import com.xinai.vo.RequestVo;
import com.xinai.vo.SysBarcode;
import com.xinai.vo.SysDepartment;
import com.xinai.vo.SysUsers;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.xinai.dao.DepartmentDao;
import com.xinai.R;
import com.xinai.dao.ParamerDao;
import com.xinai.dao.SysDepartmentDao;
import com.xinai.dao.SysUsersDao;
import com.xinai.dao.sysBarcodeDao;
import com.xinai.util.AppManager;
import com.xinai.util.JsonHelper;
import com.xinai.util.Logger;
import com.xinai.util.LoginParameterUtil;
import com.xinai.util.NetUtil;
import com.xinai.util.Tools;
import com.xinai.util.gridview.MyGridAdapter;
import com.xinai.util.gridview.MyGridView;
import com.xinai.vo.Department;
import com.xinai.vo.Paramer;
import com.xinai.vo.RequestVo;
import com.xinai.vo.SysBarcode;
import com.xinai.vo.SysDepartment;
import com.xinai.vo.SysUsers;

/**
 * Title: MainActivity Description: 主界面
 *
 * @author LYJ
 *
 */
public class MainActivity extends BaseWapperActivity implements OnItemClickListener {

    private static String TAG = "MainActivity";
    private static String logout = "/pda/pdaLogin.do?loginOut";//"/login.do?logout";
    private static String getWarehouse ="/pda/pdaSelect.do?department"; //"/common.do?getWarehouse";
    private MyGridView gridview;
    private Intent intent = null;
    private DepartmentDao departmentDao = new DepartmentDao(this);
    private sysBarcodeDao sysbarcodeDao =new sysBarcodeDao(this);
    private SysDepartmentDao sysDepartmentDao=new SysDepartmentDao(this);
    private SysUsersDao sysUsersDao=new SysUsersDao(this);
    private ParamerDao paramerDao = new ParamerDao(this);

    private Paramer  lastTime;

    // 其它属性
    private long exitTime = 0; // 记录按回退键的时间间隔
    private String[] img_text = null; // 显示的文字
    private String[] img_activity = null; // 图标对应的activity
    private Integer[] imgs = null; // 图标

    private int currPage=1;

    /**
     * 初始化数据
     */
    private void getData() {



               img_activity = new String[]{"com.xinai.activity.SalesManagementActivity","com.xinai.activity.PositionManagementActivity","com.xinai.activity.InventorySheetOutLineActivity","com.xinai.activity.PosSalesManagementActivity","com.xinai.activity.OPMLoginActivity"};
               img_text = new String[]{"分销管理","仓储管理","离线盘点","零售管理","订货会中心"};
               imgs = new Integer[]{R.string.sales_manage,R.string.position_manage,R.string.out_line_inventory_sheet,R.string.posSales_manage,R.string.order_placing_meeting};


        /*   if (Boolean.valueOf(this.getString(R.string.use_position))) {
            if (LoginParameterUtil.customer != null && "1".equals(LoginParameterUtil.customer.getUserId())) {
                if (LoginParameterUtil.usingOrderGoodsModule) {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PositionManagementActivity",
                                    "com.fuxi.activity.PosSalesManagementActivity", "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.OPMLoginActivity", "com.fuxi.activity.SettingActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "仓储管理", "零售管理", "装箱扫描", "条码打印", "订货中心", "设置中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.position_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.order_placing_meeting, R.string.system_setting};
                } else {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PositionManagementActivity",
                                    "com.fuxi.activity.PosSalesManagementActivity", "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.SettingActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "仓储管理", "零售管理", "装箱扫描", "条码打印", "设置中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.position_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.system_setting};
                }
            } else {
                if (LoginParameterUtil.usingOrderGoodsModule) {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PositionManagementActivity",
                                    "com.fuxi.activity.PosSalesManagementActivity", "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.OPMLoginActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "仓储管理", "零售管理", "装箱扫描", "条码打印", "订货中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.position_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.order_placing_meeting};
                } else {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PositionManagementActivity",
                                    "com.fuxi.activity.PosSalesManagementActivity", "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "仓储管理", "零售管理", "装箱扫描", "条码打印"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.position_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print};
                }
            }
        } else {
            if (LoginParameterUtil.customer != null && "1".equals(LoginParameterUtil.customer.getUserId())) {
                if (LoginParameterUtil.usingOrderGoodsModule) {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PosSalesManagementActivity",
                                    "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.OPMLoginActivity", "com.fuxi.activity.SettingActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "零售管理", "装箱扫描", "条码打印", "订货中心", "设置中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.order_placing_meeting, R.string.system_setting,};

                } else {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PosSalesManagementActivity",
                                    "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.SettingActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "零售管理", "装箱扫描", "条码打印", "设置中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.system_setting,};

                }
            } else {
                if (LoginParameterUtil.usingOrderGoodsModule) {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PosSalesManagementActivity",
                                    "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity", "com.fuxi.activity.OPMLoginActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "零售管理", "装箱扫描", "条码打印", "订货中心"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print, R.string.order_placing_meeting};

                } else {
                    img_activity =
                            new String[] {"com.fuxi.activity.BaseInformationActivity", "com.fuxi.activity.SalesManagementActivity", "com.fuxi.activity.PurchaseManagementActivity", "com.fuxi.activity.WarehouseManagementActivity", "com.fuxi.activity.PosSalesManagementActivity",
                                    "com.fuxi.activity.PackingBoxActivity", "com.fuxi.activity.BarcodePrintActivity"};
                    img_text = new String[] {"基本资料", "分销管理", "采购管理", "库存管理", "零售管理", "装箱扫描", "条码打印"};
                    imgs = new Integer[] {R.string.base_info, R.string.sales_manage, R.string.purchase_manage, R.string.warehouse_manage, R.string.posSales_manage, R.string.packing_box, R.string.barcode_print};

                }
            }
        }
        */
    }

    /**
     * 连续按两次回退键退出程序
     */
    private void exit() {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {
            logOut();
        }
    }

    /**
     * 退出系统并注销登录信息
     */
    public void logOut() {
        boolean flag = NetUtil.hasNetwork(getApplicationContext());
        if (flag) {
            // 连接服务器
            RequestVo vo = new RequestVo();
            vo.requestUrl = logout;
            vo.context = this;
            HashMap map = new HashMap();
            map.put("onLineId", LoginParameterUtil.onLineId);
            vo.requestDataMap = map;
            super.getDataFromServer(vo, new DataCallback<JSONObject>() {
                @Override
                public void processData(JSONObject paramObject, boolean paramBoolean) {
                    AppManager.getAppManager().AppExit(getApplicationContext());
                }
            });
        } else {
            AppManager.getAppManager().AppExit(getApplicationContext());
        }
    }

    /**
     * 根据登录权限获取部门信息(用于离线盘点时使用)
     */
    private void getWarehouseList() {
        RequestVo vo = new RequestVo();
        vo.requestUrl = getWarehouse;
        vo.context = this;
        HashMap map = new HashMap();
        vo.requestDataMap = map;
        super.getDataFromServer(vo, new DataCallback<JSONObject>() {
            @Override
            public void processData(JSONObject retObj, boolean paramBoolean) {
                try {
                    if (retObj == null) {
                        return;
                    }
                    if (retObj.getBoolean("success")) {
                        JSONArray array = retObj.getJSONArray("obj");
                        List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
                        for (int i = 0; i < array.length(); i++) {
                            Map temp = new HashMap();
                            JSONObject json = array.getJSONObject(i);
                            Iterator ite = json.keys();
                            while (ite.hasNext()) {
                                String key = ite.next().toString();
                                String value = json.getString(key);
                                temp.put(key, value);
                            }
                            dataList.add(temp);
                        }
                        // 存入缓存
                        saveDepartment(dataList);
                    }
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "系统错误", Toast.LENGTH_LONG).show();
                    Logger.e(TAG, e.getMessage());
                }
            }
        });
    }

    /**
     * 保存部门
     *
     * @param
     * @param
     * @param
     */
    public void saveDepartment(List<Map<String, Object>> dataList) {
        try {
            // 检查部门表里面是否有旧数据
            Department findFirst = departmentDao.findFirst();
            if (findFirst != null) {
                departmentDao.deleteAll();
            }
            // 插入新的部门记录
            String madeDate = Tools.dateToString(new Date());
            for (int i = 0; i < dataList.size(); i++) {
                Map<String, Object> map = dataList.get(i);
                String departmentId = String.valueOf(map.get("DepartmentID"));
                String department = String.valueOf(map.get("Name"));
                int mustExistsGoodsFlag = 0;
                String mustExistsGoodsFlagStr = String.valueOf(map.get("MustExistsGoodsFlag"));
                if ("true".equals(mustExistsGoodsFlagStr)) {
                    mustExistsGoodsFlag = 1;
                }
                String departmentCode = String.valueOf(map.get("DepartmentCode"));
                Department dept = new Department(departmentId, department, mustExistsGoodsFlag, departmentCode, madeDate);
                departmentDao.insert(dept);
            }
            Log.i("ok", "部门信息存储成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {}

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            exit();
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_main);
        setTitle("主 菜 单");
        setHeadLeftVisibility(View.INVISIBLE);
    }

    @Override
    protected void setListener() {
        gridview.setOnItemClickListener(this);
    }

    @Override
    protected void processLogic() {
        // 显示按钮
        setHeadRightVisibility(View.VISIBLE);
        setHeadRightText(R.string.exit);

        if(NetUtil.hasNetwork(this)) {
            DataTask dt = new DataTask();
            dt.execute("同步数据");
        }

     /*   if (NetUtil.hasNetwork(getApplicationContext())) {
            // 获取仓库信息
            getWarehouseList();
        } */  //先不用仓位
    }

    @Override
    protected void onHeadRightButton(View v) {
        Builder dialog = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT);
        dialog.setTitle("系统提示");
        dialog.setMessage("确定要退出系统吗？");
        // 相当于点击确认按钮
        dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // 退出
                logOut();
            }
        });
        // 相当于点击取消按钮
        dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {}
        });
        dialog.create();
        dialog.show();
    }

    @Override
    protected void findViewById() {
       gridview = (MyGridView) findViewById(R.id.gv_gridview);
      // 获取数据
        getData();
        // 设置适配器
        gridview.setAdapter(new MyGridAdapter(img_text, img_activity, imgs, this));
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        try {
            if(LoginParameterUtil.salesRightMap ==null && "com.xinai.activity.SalesManagementActivity".equals(img_activity[position])) {
               Toast.makeText(this,"没有浏览权限",Toast.LENGTH_SHORT).show();
            }else {
                intent = new Intent(MainActivity.this, Class.forName(img_activity[position]));
                startActivity(intent);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
    //这里放同步数据
    @Override
    protected void onResume() {
        super.onResume();

    }


    public class DataTask extends AsyncTask<String, Integer, String> {
        //在执行实际的后台操作前被UI Thread调用
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showProgressDialog();
        }
        //在onPreExecute执行，该方法运行在后台线程中
        @Override
        protected String doInBackground(String... strings) {



            String lastTimeStr ="";
            lastTime=  paramerDao.find("lastTime"); //获取对象
            if(lastTime !=null)
            {
                lastTimeStr =   lastTime.getValue();
            }
            Logger.e(TAG,"lastTimeStr的值"+lastTimeStr);

           RequestVo reqVo =new RequestVo();
            reqVo.requestUrl ="/pda/pdaSelect.do?sysBarcode";
            reqVo.context=MainActivity.this;

            //格式可以自己根据需要修改
            SimpleDateFormat  lFormat   =new SimpleDateFormat("yyyy-MM-dd");//HHmmss
            String  dataStr   =   lFormat.format(new Date());
            Logger.i(TAG,"日期："+dataStr);
            HashMap map =new HashMap();
        try {
            int total = 0;
            map.put("lastTime", lastTimeStr);
            map.put("page", String.valueOf(currPage));
            map.put("rows", "1000");
            reqVo.requestDataMap = map;
            Object obj = NetUtil.post(reqVo);
            Logger.e(TAG,"obj的对象:"+obj.toString());
            JSONObject jsonObject = (JSONObject) obj;
            JSONObject json =jsonObject.getJSONObject("obj");
            total =json.getInt("total");// 测试用
            BigDecimal decimal = new BigDecimal(total).divide(new BigDecimal(1000));
            if(decimal.compareTo(new BigDecimal(1)) ==-1){
                total =1;
            }else {
                total = (int) Math.ceil(decimal.doubleValue());
            }
            Logger.e(TAG,"总页数"+total);
            //请求次数
            for(int i=1;i<=total ;i++){
                map.put("lastTime", lastTimeStr);
                map.put("page", String.valueOf(currPage));
                map.put("rows", "1000");
                reqVo.requestDataMap = map;
                Object obj2 = NetUtil.post(reqVo);

                JSONObject jsonObject1 = (JSONObject) obj2;
                JSONObject json1 =jsonObject.getJSONObject("obj");

                JSONArray jsonArray=json1.getJSONArray("results");

                if(jsonArray.length()>0){
                   List<SysBarcode> ls= com.alibaba.fastjson.JSON.parseArray(jsonArray.toString(),SysBarcode.class);
                   for(SysBarcode sysbarcode :ls) {
                       sysbarcodeDao.insert(sysbarcode);
                   }
                }
                currPage++;
            }
            //同步部门-----------------------------------------------------
            reqVo.requestUrl ="/pda/pdaSelect.do?sysDepartment";
            currPage =1;
            map.clear();
            map.put("lastTime", lastTimeStr);
            map.put("page", String.valueOf(currPage));
            map.put("rows", "1");
            reqVo.requestDataMap = map;
             obj = NetUtil.post(reqVo);
            Logger.e(TAG,"obj的对象:"+obj.toString());
             jsonObject = (JSONObject) obj;
             json =jsonObject.getJSONObject("obj");
            total =json.getInt("total");// 测试用
             decimal = new BigDecimal(total).divide(new BigDecimal(1000));
            if(decimal.compareTo(new BigDecimal(1)) ==-1){
                total =1;
            }else {
                total = (int) Math.ceil(decimal.doubleValue());
            }
            Logger.e(TAG,"总页数"+total);
            //请求次数
          for(int i=1;i<=total;i++){
              map.put("lastTime", lastTimeStr);
              map.put("page", String.valueOf(currPage));
              map.put("rows", "1000");
              reqVo.requestDataMap = map;
              Object obj2 = NetUtil.post(reqVo);

              JSONObject json1 =(JSONObject) obj2;
              JSONObject obj3=json1.getJSONObject("obj");
              JSONArray jsonArray=obj3.getJSONArray("results");

              if(jsonArray.length()>0){
                  List<SysDepartment> ls= com.alibaba.fastjson.JSON.parseArray(jsonArray.toString(),SysDepartment.class);
                  for(SysDepartment sysDepartment :ls) {
                      sysDepartmentDao.insert(sysDepartment);
                  }
              }
              currPage++;
          }
        //------------同步员工
            reqVo.requestUrl ="/pda/pdaSelect.do?sysUsers";
            currPage =1;
            map.clear();
            map.put("lastTime", lastTimeStr);
            map.put("page", String.valueOf(currPage));
            map.put("rows", "1");
            reqVo.requestDataMap = map;
            obj = NetUtil.post(reqVo);
            Logger.e(TAG,"obj的对象:"+obj.toString());
            jsonObject = (JSONObject) obj;
            json =jsonObject.getJSONObject("obj");
            total =json.getInt("total");// 测试用
            decimal = new BigDecimal(total).divide(new BigDecimal(1000));
            if(decimal.compareTo(new BigDecimal(1)) ==-1){
                total =1;
            }else {
                total = (int) Math.ceil(decimal.doubleValue());
            }
            Logger.e(TAG,"总页数"+total);
            //请求次数
            for(int i=1;i<=total;i++){
                map.put("lastTime", lastTimeStr);
                map.put("page", String.valueOf(currPage));
                map.put("rows", "1000");
                reqVo.requestDataMap = map;
                Object obj2 = NetUtil.post(reqVo);

                JSONObject obj4 = (JSONObject) obj2;
                JSONObject json1 =obj4.getJSONObject("obj");

                JSONArray jsonArray=json1.getJSONArray("results");

                if(jsonArray.length()>0){
                    List<SysUsers> ls= com.alibaba.fastjson.JSON.parseArray(jsonArray.toString(),SysUsers.class);
                    for(SysUsers sysUsers :ls) {
                        sysUsersDao.insert(sysUsers);
                    }
                }
                currPage++;
            }
            SimpleDateFormat ldf=new SimpleDateFormat("yyyy-MM-dd");
            lastTime =new Paramer("lastTime",ldf.format(new Date()));
            if(lastTimeStr ==null || "".equals(lastTimeStr)){
                        paramerDao.insert(lastTime);
            }else { //更新


                paramerDao.update(lastTime);
            }
            lastTime=  paramerDao.find("lastTime"); //获取对象
            System.out.println("最后的同步时间:"+lastTime.getValue());

            //查询数据看看
           List<SysBarcode> lb =sysbarcodeDao.getList("12");
            for(int k=0;k<lb.size();k++){
                Logger.e(TAG,"条码数据："+lb.get(k).getBarcode()+"\n"+"货品名称："+lb.get(k).getProductName()+"\n货品编码:"+lb.get(k).getId());
                //Logger.e(TAG,"产品名称："+);
            }

        //    Logger.e(TAG,"总记录数："+sysbarcodeDao.total());

            closeProgressDialog();
        }catch (Exception e){
            closeProgressDialog();
            e.printStackTrace();

        }

            return null;
        }
        //在publishProgress被调用后，UI thread会调用这个方法
        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
        }
        //doInBackground方法执行完后被UI thread执行
        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
          //  closeProgressDialog();
        }
    }




}
